Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the gf gen ctrl command to support nested/multi-level API directories and updates related test fixtures to match the new directory structure.
- Introduces
generateByModulesfor recursive module generation. - Updates testdata paths in unit tests (
defaultandmergescenarios). - Replaces deprecated
gfile.Removecalls withgfile.RemoveAll.
Reviewed Changes
Copilot reviewed 42 out of 50 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| cmd/gf/internal/cmd/genctrl/genctrl.go | Added generateByModules to recursively process subfolders. |
| cmd/gf/internal/cmd/cmd_z_unit_gen_ctrl_test.go | Adjusted test paths and cleanup to use RemoveAll. |
| cmd/gf/internal/cmd/testdata/genctrl/* | Added/updated multi-level controller and API fixtures. |
Contributor
|
求改一下gen pb 目前只生成controller到一个文件 |
|
有机会合并吗,挺需要这个功能的 |
hailaz
approved these changes
Dec 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
介绍
有时候某些项目没有达到要使用大仓模式的程度,使用单仓便可以完成业务。
但是
gf gen ctrl只能支持module/version这种目录,譬如user/v1,像api/app/user/v1,api/admin/admin/v1这种接口便无能为力。本
PR改进了生成模式,现在使其可以更灵活的生成控制器,包括多级目录生成。例子
在
api下定义了app和admin两个模块,其中app下又定义了/user/v1和/user/user_ext/v1,最后生成如红框所示:这是一个复杂的例子,用来检测代码的健壮性。
在真实的项目中,应该类似
api/app/user/v1,api/app/user_ext/v1。其他
/testdata/genctrl和/testdata/genctrl-merge中,现在更改为/testdata/genctrl/default和/testdata/genctrl/merge;gfile.Remove。增进来源:Issue和官网评论